//
// Copyright (c) 2009 All Right Reserved
//
// vl
//
// 2018-12-01
// Contains ...
namespace LargoPanels.Editor
{
using LargoCommon.Abstract;
using LargoCommon.Interfaces;
using LargoCommon.Music;
using LargoPanels.Abstract;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
///
/// Interact logic for ContentCell.
///
public class ContentCell : BaseCell
{
#region Constructors
/// Initializes a new instance of the class.
/// The given master - editor space.
/// Zero-based index of the given line.
/// Zero-based index of the given bar.
[JetBrains.Annotations.UsedImplicitlyAttribute]
public ContentCell(EditorSpace givenMaster, int givenLineIdx, int givenBarIdx) : base(givenMaster) {
this.LineIndex = givenLineIdx;
this.BarIndex = givenBarIdx;
this.Width = SeedSize.BasicWidth;
this.Height = SeedSize.BasicHeight;
//// this.RhythmicStructure = new RhythmicStructure(RhythmicSystem.GetRhythmicSystem(RhythmicDegree.Structure, 12), 0);
}
/// Initializes a new instance of the class.
/// The given master - editor space.
/// The given element.
public ContentCell(EditorSpace givenMaster, IAbstractElement givenElement) : base(givenMaster) {
this.Bar = givenElement.Bar;
this.Line = givenElement.Line;
this.Element = (MusicalElement)givenElement;
this.BarIndex = this.Bar.BarNumber - 1;
this.LineIndex = this.Line.LineIndex;
this.Point = this.Element.Point;
this.Width = SeedSize.BasicWidth;
this.Height = SeedSize.CurrentHeight - SeedSize.BasicMargin;
//// this.RenderSize = new System.Windows.Size(this.Width, this.Height);
this.HasContent = this.Element.HasContent;
this.Status = this.Element.Status;
}
#endregion
#region Properties - Main
///
/// Gets or sets the bar.
///
///
/// The bar.
///
public IAbstractBar Bar { get; set; }
///
/// Gets or sets the line.
///
///
/// The line.
///
public IAbstractLine Line { get; set; }
///
/// Gets or sets the first unit.
///
///
/// The first unit.
///
public MusicalElement Element { get; set; }
///
/// Gets the identifiers.
///
///
/// The identifiers.
///
public IList Identifiers {
get {
var items = this.Element.Identifiers.ToList();
var item = new KeyValuePair("Rhythmic face", this.Status.RhythmicFace?.Name);
items.Add(item);
item = new KeyValuePair("Melodic face", this.Status.MelodicFace?.Name);
items.Add(item);
return items;
}
}
#endregion
#region Properties - Status
/// Gets or sets the status.
/// The status.
public LineStatus Status { get; set; }
#endregion
#region Properties - Content
///
/// Gets or sets a value indicating whether this instance has content.
///
///
/// true if this instance has content; otherwise, false.
///
public bool HasContent { get; set; }
/// Gets or sets the rhythmic structure.
/// The rhythmic structure.
public RhythmicStructure RhythmicStructure { get; set; }
#endregion
#region Public methods
///
/// Sets the data.
///
/// The given data.
/// Returns value.
public bool SetData(IDataObject givenData) {
bool change = false;
if (givenData.GetData("RhythmicFace") is RhythmicFace rhythmicFace) {
this.Status.RhythmicFace = rhythmicFace;
change = true;
}
if (givenData.GetData("MelodicFace") is MelodicFace melodicFace) {
this.Status.MelodicFace = melodicFace;
change = true;
}
if (givenData.GetData("MelodicFunction") is MelodicFunction melodicFunction) {
this.Status.MelodicFunction = melodicFunction;
change = true;
}
if (givenData.GetData("MelodicShape") is MelodicShape melodicShape) {
this.Status.MelodicShape = melodicShape;
change = true;
}
if (change) {
this.formattedText = null;
}
return change;
}
/// Gets or sets the formatted text.
/// The formatted text.
public override FormattedText FormattedText() {
//// if (this.formattedText != null) {
//// return this.formattedText; }
var sb = new StringBuilder();
if (this.Master.IsMusicEditor) {
sb.Append(this.Element.DisplayText);
}
else {
var status = this.Element?.Status;
sb.AppendLine(status.MelodicFace?.Name);
sb.Append(status.RhythmicFace?.Name);
}
//// sb.Append(this.RhythmicStructure.ElementSchema);
this.formattedText = AbstractText.Singleton.FormatText(sb.ToString(), (int)this.Width - SeedSize.BasicMargin);
return this.formattedText;
}
#endregion
#region Copy-Paste
///
/// Copies this instance.
///
public override void Copy() {
System.Text.StringBuilder sb = new System.Text.StringBuilder();
//// Cycle for all units ???
var xstatus = this.Element.Status.GetXElement;
var item = xstatus.ToString();
sb.AppendFormat("{0};", item);
System.Windows.Clipboard.SetText(sb.ToString());
//// Clipboard.SetDataObject(xstatus);
System.Console.Beep(880, 180);
}
///
/// Pastes this instance.
///
public override void Paste() {
var s = System.Windows.Clipboard.GetText();
if (string.IsNullOrEmpty(s)) {
return;
}
var splitArray = s.Split(';');
if (!splitArray.Any()) {
return;
}
var item = splitArray.First();
var xstatus = System.Xml.Linq.XElement.Parse(item);
var header = this.Master.GetMusicalHeader;
var status = new LineStatus(xstatus, header);
this.Status.SetStatus(status, EditorContent.Cell);
System.Console.Beep(990, 180);
var space = this.Master as EditorSpace;
space?.InvalidateVisual();
//// this.RedrawCell(false);
}
#endregion
}
}